package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.PartnerCustomerHisVO;
import com.yunxi.sat.service.PartnerCustomerHisDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 渠道客户关系历史 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/admin/partnerCustomerHis")
@Api(tags = "sat:partnerCustomerHis", description = "渠道客户关系历史接口")
public class PartnerCustomerHisController {
    private static final Logger logger = LoggerFactory.getLogger(PartnerCustomerHisController.class);

    @Autowired
    PartnerCustomerHisDubboService partnerCustomerHisDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(PartnerCustomerHisVO partnerCustomerHisVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(partnerCustomerHisDubboService.findPageByVO(partnerCustomerHisVO, pageNum, pageSize, loginInfo));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType = "query", name = "partnerCustomerId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String partnerCustomerId, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(partnerCustomerHisDubboService.getById(partnerCustomerId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody PartnerCustomerHisVO partnerCustomerHisVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerCustomerHisDubboService.saveOrUpdate(partnerCustomerHisVO, loginInfo);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerCustomerHisDubboService.del(list, loginInfo.getUserCode());
        return ResponseUtil.ok("success");
    }

}
